/**
 * TorrentJEDI
 * 		Torrent Java Episode Download Interface
 */
package torrentjedi.util;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author Alper Kokmen
 *
 */
public class JEDIValidator {
	
	public static Boolean validateText(String input, int min, int max) {
		if (input.length() < min || input.length() > max) {
			return false;
		} else {
			return true;
		}
		
	}
	
	public static Boolean validateInteger(String input, int min, int max) {
		try {
			int inputAsInteger = Integer.parseInt(input);
			
			if (inputAsInteger < min || inputAsInteger > max) {
				return false;
			} else {
				return true;
			}
			
		} catch (NumberFormatException e) {
			System.out.println("ERROR@TorrentJEDI:JEDIValidator validateInteger cannot parse the input");
			return false;
		}
	}
	
	public static Boolean validateURL(String input) {
		try {
			URL url = new URL(input);
			url.toString();	// dummy statement
			return true;
		} catch (MalformedURLException e) {
			System.out.println("ERROR@TorrentJEDI:JEDIValidator validateURL malformed url specified");
			return false;
		}
	}
}
